import Vue from 'vue'
import VueRouter from 'vue-router'

import store from '../util/store'

Vue.use(VueRouter)


let router = new VueRouter({
	
	routes: [{
			path: '/',
			name: 'Home',
			component: () => import('@/views/home/home'),
			children: [{
					path: '/user',
					name: 'User',
					component: () => import('@/views/user/user')
				},
				{
					path: '/role',
					name: 'RoleList',
					component: () => import('@/views/role')
				},
				{
					path: '/menu',
					name: 'MenuList',
					component: () => import('@/views/menu')
				},
				{
					path: '/constant_type',
					name: 'ConstantType',
					component: () => import('@/views/constant_type')
				},
				{
					path: '/constant_item',
					name: 'ContantItem',
					component: () => import('@/views/constant_item')
				},
				{
					path: '/regist',
					name: 'Regist',
					component: () => import('@/views/regist')
				},
				{
					path: '/regist_level',
					name: 'RegistLevel',
					component: () => import('@/views/regist_level')
				},
				{
					path: '/dept',
					name: 'Dept',
					component: () => import('@/views/dept')
				},
				{
					path: '/check_item',
					name: 'CheckItem',
					component: () => import('@/views/check_item')
				},
				{
					path: '/inspect_item',
					name: 'InspectItem',
					component: () => import('@/views/inspect_item')
				},
				{
					path: '/doctor',
					name: 'DoctorHome',
					component: () => import('@/views/doctor')
				},
				{
					path: '/unregist',
					name: 'UnRegist',
					component: () => import('@/views/regist/unregist')
				},
				{
					path: '/fee',
					name: 'Fee',
					component: () => import('@/views/regist/fee')
				},
				{
					path: '/refund',
					name: 'Refund',
					component: () => import('@/views/regist/refund')
				},
				{
					path: '/status',
					name: 'Status',
					component: () => import('@/views/status')
				}
			]
		},
		{
			path: '/login',
			name: 'Login',
			component: () => import('@/views/login/login')
		}


	]


})

const whitelist = ['/login']


router.beforeEach((to, from, next) => {
   //在白名单里面，直接放行
  if(whitelist.indexOf(to.path) !== -1){
	  next(); 
  }else{
	  //是否是登录的状态
	  let user = store.getters.getuser;
	  if(user){
		 next();//放行  
	  }else{   //跳转到登录
		 next("/login");  
	  }
	  //to-login
  }
 
  
 
  
})



export default router;